<template>
	<view :style="{ height: windowHeight, overflow: 'hidden' }">
		<!-- 搜索 -->
		<search @search="search"></search>
		<!-- 焦点图 -->
		<swiper class="banner" indicator-dots indicator-color="rgba(255, 255, 255, 0.6)" indicator-active-color="#fff">
			<swiper-item v-for="item in swiperList" :key="item.goods_id">
				<navigator :url="`/subpkg/pages/goods/index?id=${item.goods_id}`">
					<image :src="item.image_src"></image>
				</navigator>
			</swiper-item>
		</swiper>
		<!-- 导航条 -->
		<view class="navs">
			<navigator v-for="item in categaryList" :key="item.name"
				:open-type="item.open_type ? 'switchTab' : 'navigate'"
				:url="item.open_type ? '/pages/category/index' : `/subpkg/pages/list/index?name=${item.name}`">
				<image :src="item.image_src"></image>
			</navigator>
			<!-- <navigator open-type="navigate" url="/subpkg/pages/list/index">
				<image src="http://static.botue.com/ugo/uploads/icon_index_nav_3@2x.png"></image>
			</navigator>
			<navigator url="/subpkg/pages/list/index">
				<image src="http://static.botue.com/ugo/uploads/icon_index_nav_2@2x.png"></image>
			</navigator>
			<navigator url="/subpkg/pages/list/index">
				<image src="http://static.botue.com/ugo/uploads/icon_index_nav_1@2x.png"></image>
			</navigator> -->
		</view>
		<!-- 楼层 -->
		<view class="floors">
			<view class="floor">
				<view class="title">
					<image src="http://static.botue.com/ugo/uploads/pic_floor01_title.png"></image>
				</view>
				<view class="items">
					<navigator url="/subpkg/pages/list/index">
						<image src="http://static.botue.com/ugo/uploads/pic_floor01_1@2x.png"></image>
					</navigator>
					<navigator url="/subpkg/pages/list/index">
						<image src="http://static.botue.com/ugo/uploads/pic_floor01_2@2x.png"></image>
					</navigator>
					<navigator url="/subpkg/pages/list/index">
						<image src="http://static.botue.com/ugo/uploads/pic_floor01_3@2x.png"></image>
					</navigator>
					<navigator url="/subpkg/pages/list/index">
						<image src="http://static.botue.com/ugo/uploads/pic_floor01_4@2x.png"></image>
					</navigator>
					<navigator url="/subpkg/pages/list/index">
						<image src="http://static.botue.com/ugo/uploads/pic_floor01_5@2x.png"></image>
					</navigator>
				</view>
			</view>
			<view class="floor">
				<view class="title">
					<image src="http://static.botue.com/ugo/uploads/pic_floor02_title.png" />
				</view>
				<view class="items">
					<navigator url="/subpkg/pages/list/index">
						<image src="http://static.botue.com/ugo/uploads/pic_floor02_1@2x.png"></image>
					</navigator>
					<navigator url="/subpkg/pages/list/index">
						<image src="http://static.botue.com/ugo/uploads/pic_floor02_2@2x.png"></image>
					</navigator>
					<navigator url="/subpkg/pages/list/index">
						<image src="http://static.botue.com/ugo/uploads/pic_floor02_3@2x.png"></image>
					</navigator>
					<navigator url="/subpkg/pages/list/index">
						<image src="http://static.botue.com/ugo/uploads/pic_floor02_4@2x.png"></image>
					</navigator>
					<navigator url="/subpkg/pages/list/index">
						<image src="http://static.botue.com/ugo/uploads/pic_floor02_5@2x.png"></image>
					</navigator>
				</view>
			</view>
			<view class="floor">
				<view class="title">
					<image src="http://static.botue.com/ugo/uploads/pic_floor03_title.png"></image>
				</view>
				<view class="items">
					<navigator url="/subpkg/pages/list/index">
						<image src="http://static.botue.com/ugo/uploads/pic_floor03_1@2x.png"></image>
					</navigator>
					<navigator url="/subpkg/pages/list/index">
						<image src="http://static.botue.com/ugo/uploads/pic_floor03_2@2x.png"></image>
					</navigator>
					<navigator url="/subpkg/pages/list/index">
						<image src="http://static.botue.com/ugo/uploads/pic_floor03_3@2x.png"></image>
					</navigator>
					<navigator url="/subpkg/pages/list/index">
						<image src="http://static.botue.com/ugo/uploads/pic_floor03_4@2x.png"></image>
					</navigator>
					<navigator url="/subpkg/pages/list/index">
						<image src="http://static.botue.com/ugo/uploads/pic_floor03_5@2x.png"></image>
					</navigator>
				</view>
			</view>
		</view>
		<!-- 回到顶部 -->
		<view class="goTop icon-top" @click="goTop"></view>
	</view>
</template>

<script>
	import search from '@/components/search/index.vue'
	export default {
		components: {
			search
		},
		onLoad() {
			this.getSwiperList()
			this.getCategaryList()
		},
		data() {
			return {
				swiperList: [],
				categaryList: [],
				windowHeight: 'auto'
			}
		},
		methods: {
			// 获取子组件传递的窗口高度
			search(height) {
				console.log(height);
				this.windowHeight = height
			},
			// 获取轮播图数据
			async getSwiperList() {
				const res = await uni.$http.get('/api/public/v1/home/swiperdata')
				// console.log(res.data.message);
				this.swiperList = res.data.message
			},
			// 获取分类导航数据
			async getCategaryList() {
				const res = await uni.$http.get('/api/public/v1/home/catitems')
				console.log(res.data.message);
				this.categaryList = res.data.message
			},
			// 回到顶部
			goTop() {
				uni.pageScrollTo({
					scrollTop: 0
				})
			}
		},
		// 用户下拉刷新时，会触发的函数
		onPullDownRefresh() {
			// 重新获取首页数据
			this.getSwiperList()
			this.getCategaryList()
		}
	}
</script>

<style scoped lang="scss">
	.banner {
		width: 100%;
		height: 340rpx;

		image {
			width: 100%;
			height: 340rpx;
		}
	}

	.navs {
		display: flex;
		justify-content: space-between;
		padding: 30rpx 44rpx;

		image {
			width: 128rpx;
			height: 140rpx;
		}
	}

	.floor {

		.title {
			width: 750rpx;
			height: 60rpx;
			padding: 20rpx 0 0 8rpx;
			background-color: #f4f4f4;
		}

		.items {
			padding: 20rpx 16rpx;
			overflow: hidden;

			navigator {
				width: 193rpx;
				height: 188rpx;
				margin-left: 10rpx;
				margin-bottom: 10rpx;
				float: left;
			}

			navigator:first-child {
				width: 232rpx;
				height: 386rpx;
				margin-left: 0rpx;
			}

			navigator:nth-child(2),
			navigator:nth-child(5) {
				width: 273rpx;
			}
		}

		&:first-child {

			.items {

				navigator {
					width: 233rpx;
				}
			}
		}
	}

	.goTop {
		position: fixed;
		bottom: 30rpx;
		/* #ifdef H5 */
		bottom: 65px;
		/* #endif */
		right: 30rpx;

		display: flex;
		justify-content: center;
		align-items: center;
		width: 100rpx;
		height: 100rpx;
		font-size: 48rpx;
		color: #666;
		border-radius: 50%;
		background-color: rgba(255, 255, 255, 0.8);
	}
</style>
